<?php if (!defined('BASEPATH')) exit('No direct access allowed.');

class User_bo extends MY_Service {

    public $uid;
    public $username;
    public $gid;
    public $groups = array();
    public $ip;
    public $info   = array();

    private $_group_info = array();
    private $_permission = array();

    private static $_user_bo = array();

    public function __construct() {
        parent::__construct();
        $this->load->model('user_model');
        log_message('debug', 'User_bo Class Initialized');
    }

    /**
     * 初始化
     *
     * @param int $uid 用户ID
     * @param boolean $fetch_all 获取数据类型
     * @return $this
     */
    public function init($uid, $fetch_all = false) {
        //$fetch_all 为 true 则获取所有数据，否则获取 min + data 数据
        $type = $fetch_all ? User_model::FETCH_ALL : (User_model::FETCH_MAIN | User_model::FETCH_DATA);
        $this->info = $uid ? $this->user_model->get_by_uid($uid, $type) : array();
        if ($this->info) {
            $this->uid = $uid;
            $this->username = $this->info['username'];
            $this->gid = $this->info['gid'];
            $this->ip = $this->info['last_login_ip'];
            if ($this->info['groups']) $this->groups = explode(',', $this->info['groups']);
            $this->groups[] = $this->gid;
        } else {
            $this->reset();
        }
        return $this;
    }

    /**
     * 用户重置操作
     *
     * @return boolean
     */
    public function reset() {
        $this->uid = 0;
        $this->gid = 2;
        $this->username = '游客';
        $this->info = array();
    }

}

/* End of file User_bo.php */
/* Location: ./application/service/user/bo/User_bo.php */
